{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3fdccdea",
   "metadata": {},
   "source": [
    "# First Agentic AI workflow with Local LLM (Ollama)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d97ba32",
   "metadata": {},
   "source": [
    "## Problem Statement\n",
    "- First ask the LLM to pick a business area that might be worth exploring for an Agentic AI opportunity.\n",
    "- Then ask the LLM to present a pain-point in that industry - something challenging that might be ripe for an Agentic solution.\n",
    "- Finally have 3 third LLM call propose the Agentic AI solution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0fd3d03f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Make sure Ollama is installed and running\n",
    "# If not installed - install by visiting https://ollama.com\n",
    "# Go to http://localhost:11434 - to see 'Ollama is running'\n",
    "\n",
    "# Pull the llama3.2 model\n",
    "!ollama pull llama3.2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4bed0a24",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import OpenAI\n",
    "from openai import OpenAI\n",
    "# Initialize the Ollama client\n",
    "ollama_client = OpenAI(base_url=\"http://localhost:11434/v1\", api_key=\"ollama\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "281b3ff4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import Markdown for display \n",
    "from IPython.display import Markdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fd51cfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define first message\n",
    "first_message = [{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": \"Pick a business area that might be worth exploring for an Agentic AI opportunity.\"\n",
    "}]\n",
    "# Make the first call\n",
    "first_response = ollama_client.chat.completions.create(\n",
    "    model=\"llama3.2\",\n",
    "    messages=first_message\n",
    ")\n",
    "business_idea = first_response.choices[0].message.content\n",
    "display(Markdown(business_idea))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da3fc185",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define second message\n",
    "second_message = [{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": f\"Please present a pain-point in the {business_idea} industry that might be ripe for an Agentic solution.\"\n",
    "}]\n",
    "# Make the ssecond call\n",
    "second_response = ollama_client.chat.completions.create(\n",
    "    model=\"llama3.2\",\n",
    "    messages=second_message\n",
    ")\n",
    "pain_point = second_response.choices[0].message.content\n",
    "display(Markdown(pain_point))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8c996c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define third message\n",
    "third_message = [{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": f\"Please present an Agentic solution to the {pain_point} in the {business_idea} industry.\"\n",
    "}]\n",
    "# Make the third call\n",
    "third_response = ollama_client.chat.completions.create(\n",
    "    model=\"llama3.2\",\n",
    "    messages=third_message\n",
    ")\n",
    "agentic_solution = third_response.choices[0].message.content\n",
    "display(Markdown(agentic_solution))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
